﻿// Inner Fire 游戏引擎库
// ModelMaterial - 模型贴图
//
// Copyright (c) 2025 by 尔西大帝. All rights reserved.
//
// 所属层级：应用层(4)
// 用于模型贴图。
//
// Author: 尔西大帝
// Email: 2670613871@qq.com
// Created: 2025-03-12

#pragma once

#include <static_string.h>
#include <xml_reader.h>

namespace ifire::game {

#define ARRAY_SIZE_IN_ELEMENTS(a) (sizeof(a) / sizeof(a[0]))
constexpr auto INVALID_MATERIAL = 0xFFFFFFFF;

struct ModelMaterialInfo {
  int index;
  ikit::sstr name;
  ikit::sstr material;

  ModelMaterialInfo() : index(-1), name(), material() {};
  ModelMaterialInfo(const ikit::XmlNode& node, int material_index)
      : index(material_index), name(node("Name")), material(node("Material")) {}

  bool empty() const { return name.empty(); }
};



class ModelMaterialList {
public:
  ModelMaterialList(const ikit::XmlNode& node) {
    items_ = XmlNode_ReadItems<ModelMaterialInfo>(node, "Material");
  }

  const ModelMaterialInfo& GetInfo(int index) const {
    static ModelMaterialInfo EMPTY_MATERIAL_INFO{};
    if (index < 0 || index >= items_.size()){
      return EMPTY_MATERIAL_INFO;
    }
    return items_[index];

  }
  eastl::vector<ModelMaterialInfo>& Items() { return items_; }

private:
  eastl::vector<ModelMaterialInfo> items_;
};

} // namespace ifire::game